/**
 * Created by JOKER on 2017/9/15.
 */
'use strict';
(function (window, angular, undefined) {
    app.service("customerService", customerService);
    customerService.$inject = ['$http', '$q'];// 注入依赖
    function customerService($http, $q) {
        var services = {
            findAll: findAll,
            findOne: findOne,
            save: save,
            update: update,
            remove: remove,
            postSend: postSend
        }
        return services;

        function findAll() {
            var deferred = $q.defer();
            postSend("customer/findAll.do").then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function findOne(formObj) {
            var deferred = $q.defer();
            postSend("customer/findOne.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function save(formObj) {
            var deferred = $q.defer();
            postSend("customer/save.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function update(formObj) {
            var deferred = $q.defer();
            postSend("customer/update.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function remove(formObj) {
            var deferred = $q.defer();
            postSend("customer/remove.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function postSend(url, formObj) {
            var deferred = $q.defer();
            $http({
                method: 'post',
                url: url,
                data: formObj
            }).then(function successCallback(response) {
                return deferred.resolve(response.data);
            }, function errorCallback(response) {
                return deferred.reject(response.data);
            });
            return deferred.promise;
        }
    }


    app.service("productService", productService);
    productService.$inject = ['$http', '$q'];// 注入依赖
    function productService($http, $q) {
        var services = {
            findAll: findAll,
            findOne: findOne,
            save: save,
            update: update,
            remove: remove,
            postSend: postSend
        }
        return services;

        function findAll() {
            var deferred = $q.defer();
            postSend("product/findAll.do").then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function findOne(formObj) {
            var deferred = $q.defer();
            postSend("product/findOne.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function save(formObj) {
            var deferred = $q.defer();
            postSend("product/save.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function update(formObj) {
            var deferred = $q.defer();
            postSend("product/update.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function remove(formObj) {
            var deferred = $q.defer();
            postSend("product/remove.do", formObj).then(function (response) {
                return deferred.resolve(response)
            })
            return deferred.promise;
        }

        function postSend(url, formObj) {
            var deferred = $q.defer();
            $http({
                method: 'post',
                url: url,
                data: formObj
            }).then(function successCallback(response) {
                return deferred.resolve(response.data);
            }, function errorCallback(response) {
                return deferred.reject(response.data);
            });
            return deferred.promise;
        }
    }
})(window, window.angular);
